home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8059 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  44 lines

  1. Path: fmsu03.fm.intel.com!frx215!tomtzigt
  2. From: tomtzigt@frx215.intel.com (Theodore Omtzigt - MPG MAP - FOLSOM)
  3. Newsgroups: comp.lang.c++
  4. Subject: const usage as #define
  5. Date: 14 Feb 1996 01:01:23 GMT
  6. Organization: Intel Corporation
  7. Distribution: ca
  8. Message-ID: <4frc93$2s8@fmsu03.fm.intel.com>
  9. NNTP-Posting-Host: frx215.fm.intel.com
  10.  
  11. We are trying to port a piece of C++ code to different platforms.
  12. The code was developed with GNU g++, but we would like to use
  13. the native compilers that come with the different platforms.
  14. On IBM we use c++, on HP we use cfront, and on NT we use VC++.
  15. Now the following situation arises: given this piece of code
  16.  
  17. class foo {
  18.     private:
  19.         const int SIZE = 10;
  20.         int array[SIZE];
  21.     public:
  22.         foo();
  23. };
  24.  
  25. The intend has probably been to use the 'const int SIZE' like a 
  26. #define macro to parameterize the static allocation of 'array'.
  27. GNU g++ has no problem with this intend, and IBM c++ also accepts
  28. this const initializer, but Cfront and VC++ do like the const
  29. initialization. If you then try to use the foo bla : SIZE(10)
  30. style to initialize the const int SIZE then you run in the 
  31. problem of not being able to compile int array[SIZE] appropriately.
  32.  
  33. What is the proper C++ way of doing the above?
  34.  
  35. Since I don't read this news group regularly, please respond directly 
  36. through email. Thanks in advance,
  37.  
  38. Theo
  39. -- 
  40. Dr. E. Theodore L. Omtzigt                         Intel Corporation
  41. Staff Computer Architect                           1900 Prairie City Road
  42. MAP-Folsom                                         Mail stop: FM5-08
  43. tel. (916) 356 3696                                Folsom, CA 95630
  44.